package com.xy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  Web自定义配置类
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    //重写视图解析
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //视图解析配置
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }

    //自定义国际化组件,设置地区 语言
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

    //重写添加自定义拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //addPathPatterns:拦截所有请求，excludePathPatterns：排除登录页面，项目根目录，登录的contoller，和静态资源
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html","/","/user/login","/js/**","/css/**","/img/**");
    }
}
